import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:qaun_ni_dev/utils/toast.dart';
import 'package:qaun_ni_dev/utils/request.dart';
import 'package:qaun_ni_dev/model/active_model.dart';


class ActiveProvider with ChangeNotifier {

  String activeUrl = '';
  int page = 1;
  var postType;
  List<ActiveData> activeListData = [];

  getActiveList(context) async{
    page = 1;
    activeListData = [];
    var formData = {
      'currentPage': page,
      'postType':postType
    };
    await requestPost(context, '/check/postCheckList',formData: formData).then((value){
      var res = json.decode(value.toString());
      var tempData = ActiveModel.fromJson(res);
      if(tempData.data.length > 0) {
        activeListData = tempData.data;
      } else {
        return Toast.toast(context,msg: '暂无数据');
      }
      notifyListeners();
    });
  }

  getActiveMoreList(context) async{
    page++;
    var formData = {
      'currentPage': page,
      'postType':postType
    };
    await requestPost(context, '/check/reportList',formData: formData).then((value){
      var res = json.decode(value.toString());
      var tempData = ActiveModel.fromJson(res);
      if(tempData.code == 200) {
        var tempMoreData = tempData.data;
        if(tempMoreData.length > 0 ) {
          activeListData.addAll(tempMoreData);
        } else {
          Toast.toast(context,msg: '已经没有更多数据了哦！');
        }
      }
    });
    notifyListeners();
  }



  isAgreeUserActive(context,value)async {
     await requestPost(context, '/check/postCheck',formData: value).then((value){
       var res = json.decode(value.toString());
       if(res['code'] == 200) {
         Toast.toast(context,msg: '操作成功');
         Navigator.pushNamed(context, '/activePage');
       } else {
         Toast.toast(context,msg: '操作失败了,请重试');
         Navigator.pushNamed(context, '/activePage');
       }
     });

    notifyListeners();
  }


  changeTypeValue (value) {
    postType = value;
    notifyListeners();
  }


  getActiveVideoUrl (url) {
    activeUrl = url;
    notifyListeners();
  }
}

